<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>订单管理</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<header th:replace="common/cms_top"></header>
<div class="container mt-4">

    <h1>订单列表</h1>
    <a style="float: right;background-color: #4CAF50; color: white" class="btn btn-primary mb-3" href="/orderDeliveryForm">查看发货单</a>
    <table class="table table-striped table-bordered">
        <thead class="table-dark">
        <tr>
            <th>Order ID</th>
            <th>User ID</th>
            <th>Order Date</th>
            <th>T</th>
            <th>Bill Address</th>
            <th>Ship Address</th>
            <th>Action</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="order : ${session.orderList}">
            <td th:text="${order.orderid}"></td>
            <td th:text="${order.userid}"></td>
            <td th:text="${#dates.format(order.orderdate, 'yyyy-MM-dd')}"></td>
            <td th:text="${'$' + #numbers.formatDecimal(order.totalprice, 1, 2)}"></td>

            <td>
                <div th:text="${order.billtofirstname + ' ' + order.billtolastname}"></div>
                <div th:text="${order.billaddr1}"></div>
                <div th:text="${order.billaddr2}"></div>
                <div th:text="${order.billcity + ', ' + order.billstate + ' ' + order.billzip}"></div>
                <div th:text="${order.billcountry}"></div>
            </td>

            <td>
                <div th:text="${order.shiptofirstname + ' ' + order.shiptolastname}"></div>
                <div th:text="${order.shipaddr1}"></div>
                <div th:text="${order.shipaddr2}"></div>
                <div th:text="${order.shipcity + ', ' + order.shipstate + ' ' + order.shipzip}"></div>
                <div th:text="${order.shipcountry}"></div>
            </td>

            <td>
                <div class="btn-group-vertical">
                    <a style="background-color: #4CAF50; color: white" th:href="@{/orderDetailForm(orderId=${order.orderid})}"
                       class="btn btn-sm btn-primary mb-1">Details</a>

<!--                    <form th:action="@{/order/deliveryGoods(orderId=${order.orderid})}"-->
<!--                          method="post" class="mb-1">-->
<!--                        <button type="submit" class="btn btn-sm btn-success w-100">发货</button>-->
<!--                    </form>-->
                    <a style="background-color: #4CAF50; color: white" th:href="@{/order/deliveryGoods(orderId=${order.orderid})}"
                       class="btn btn-sm btn-primary mb-1">Delivery</a>

                    <a style="background-color: #4CAF50; color: white" th:href="@{/orderUpdateForm(orderId=${order.orderid})}"
                       class="btn btn-sm btn-warning mb-1">Update</a>

                    <form th:action="@{/order/delete(orderId=${order.orderid})}"
                          method="post" onsubmit="return confirm('确认删除？');">
                        <button style="background-color: #4CAF50; color: white" type="submit" class="btn btn-sm btn-danger w-100">Delete</button>
                    </form>
                </div>
            </td>
        </tr>
        </tbody>
    </table>
</div>
<header th:replace="common/bottom"></header>
</body>
</html>